import {querySysDictListPage} from '@/api/system/param/sysDictApi';
import {querySysParamListPage} from '@/api/system/param/sysParamApi';
import {queryGeneralBizDictListPage} from '@/api/general/param/generalBizDictApi';
import {queryGeneralBizParamListPage} from '@/api/general/param/generalBizParamApi';


import {reqCommonMsg} from '@/util/reqCommonMsg';

/**
 * 获取系统参数
 */
export async function getSysParam(paramKey){
  let returnValue = {};
  let reqParams =  {
    singleBody:  {
      paramKey: paramKey
    },
    currentPage: 1, 
    pageSize: 9999
  }
  let commonData = reqCommonMsg(reqParams)
  await querySysParamListPage(commonData).then(res => {
    res.data.body.listBody.forEach(element => {
      returnValue[element.paramKey] = element.paramValue;
    });
  }, error => {
  }); 
  return returnValue;
}
/**
 * 获取业务参数
 */
export async function getBizParam(paramKey){
  let returnValue = {};
  let reqParams =  {
    singleBody:  {
      paramKey: paramKey
    },
    currentPage: 1, 
    pageSize: 9999
  }
  let commonData = reqCommonMsg(reqParams)
  await queryGeneralBizParamListPage(commonData).then(res => {
    res.data.body.listBody.forEach(element => {
      returnValue[element.paramKey] = element.paramValue;
    });
  }, error => {
  }); 
  return returnValue;
}
/**
 * 获取系统字典参数
 */
export async function getSysDict(dictNo){
  let returnValue = {};
  let reqParams =  {
    singleBody:  {
      dictNo: dictNo
    },
    currentPage: 1, 
    pageSize: 9999
  }
  let commonData = reqCommonMsg(reqParams)
  await querySysDictListPage(commonData).then(res => {
    res.data.body.listBody.forEach(element => {
      returnValue[element.dictNo] = JSON.parse(element.dictList);
    });
  }, error => {
  }); 
  return returnValue;
}

/**
 * 获取业务字典参数
 */
export async function getBizDict(dictNo){
  let returnValue = {};
  let reqParams =  {
    singleBody:  {
      dictNo: dictNo
    },
    currentPage: 1, 
    pageSize: 9999
  }
  let commonData = reqCommonMsg(reqParams)
  await queryGeneralBizDictListPage(commonData).then(res => {
    res.data.body.listBody.forEach(element => {
      returnValue[element.dictNo] = JSON.parse(element.dictList);
    });
  }, error => {
  }); 
  return returnValue;
}
export default {
  getSysDict,
  getBizDict,
  getSysParam,
  getBizParam
}
